import { getScrollParent } from '~/composables/useScrollParent';

document.documentElement.classList.add('ios');

/**
 * 避免 iOS 键盘弹出时，输入框被遮挡
 * 原理是在输入框获取焦点时，给其滚动父元素添加 padding（键盘的高度），使输入框不被遮挡
 */
// eslint-disable-next-line no-lone-blocks
{
  // const paddingScrollContentClass = 'padding-scroll-content';
  // const paddingScrollContentStyle = document.createElement('style');
  // paddingScrollContentStyle.innerHTML = `
  //   .${paddingScrollContentClass} {
  //     padding-top: 200px !important;
  //     padding-bottom: 200px !important;
  //     overscroll-behavior: none !important;
  //   }
  // `;
  // document.head.appendChild(paddingScrollContentStyle);

  // window.addEventListener('focusin', (el) => {
  //   const targetEl = el.target as Element;

  //   if (targetEl?.tagName !== 'INPUT' && targetEl?.tagName !== 'TEXTAREA')
  //     return;
  //   if (!targetEl.closest('.ant-modal-wrap'))
  //     return;

  //   const scrollParent = getScrollParent(targetEl);
  //   const scrollContent = (scrollParent === window ? document.documentElement : scrollParent) as HTMLElement;

  //   scrollContent.classList.add(paddingScrollContentClass);
  //   targetEl.addEventListener('blur', () => scrollContent.classList.remove(paddingScrollContentClass), { once: true });
  //   setTimeout(() => targetEl.scrollIntoView(), 300);
  // });
}
